import api from '@/api/common'

const actions = {
    // 获取省份
    doLoadProvince({ commit }, params) {
        return new Promise(resolve => {
            api.loadProvince(params).then(res => {
                resolve(res)
            })
        })
    },
    // 获取城市
    doLoadCity({ commit }, params) {
        return new Promise(resolve => {
            api.loadCity(params).then(res => {
                resolve(res)
            })
        })
    },
    // 获取天气
    doLoadWeather({ commit }, params) {
        return new Promise(resolve => {
            api.loadWeather(params).then(res => {
                resolve(res)
            })
        })
    },
    // 获取字典信息
    doLoadDictionary({ commit }, params) {
        return new Promise(resolve => {
            api.loadDictionary(params).then(res => {
                resolve(res)
            })
        })
    },
    // 获取字典子节点信息
    doLoadDictionaryChild({ commit }, params) {
        return new Promise(resolve => {
            api.loadDictionaryChild(params).then(res => {
                resolve(res)
            })
        })
    },
    // 新增字典信息
    doAddDictionaryInfo({ commit }, params) {
        return new Promise(resolve => {
            api.addDictionaryInfo(params).then(res => {
                resolve(res)
            })
        })
    },
    // 更新字典信息
    doEditDictionaryInfo({ commit }, params) {
        return new Promise(resolve => {
            api.editDictionaryInfo(params).then(res => {
                resolve(res)
            })
        })
    },
    // 删除字典信息
    doDeleteDictionaryInfo({ commit }, params) {
        return new Promise(resolve => {
            api.deleteDictionaryInfo(params).then(res => {
                resolve(res)
            })
        })
    },

    //查询用户配置信息
    loadUserConfig({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserConfig(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //新增用户配置信息
    addUserConfig({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.addUserConfig(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //更新用户配置信息
    editUserConfig({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.editUserConfig(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
}

export default {
    namespaced: true,
    actions
}
